//
//  FindPasswordNextViewController.m
//  JingXingApp
//
//  Created by 王亮 on 15/8/8.
//  Copyright (c) 2015年 王亮. All rights reserved.
//

#import "FindPasswordNextViewController.h"

@interface FindPasswordNextViewController ()

@property(nonatomic,strong)UITextField *passwordTextField;
@property(nonatomic,strong)UITextField *repeatTextField;

@end

@implementation FindPasswordNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self UI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)UI {
    
    self.view.backgroundColor = Color_Back_Gray;
    [self.rightBtn setTitle:@"取消" forState:UIControlStateNormal];
    
    CGFloat rate = 90.0f / 615.0f;
    CGFloat height = CGRectGetWidth(self.view.frame) * rate;
    UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(0, 12, 100, height)];
    [self.view addSubview:textField1];
    textField1.placeholder = @"输入新密码";
    [self addBackView:textField1];
    self.passwordTextField = textField1;
    
    UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(textField1.frame) + 12, 100, height)];
    [self.view addSubview:textField2];
    [self addBackView:textField2];
    textField2.placeholder = @"再次输入新密码";
    self.repeatTextField = textField2;
    
    UIImage *image = [UIImage imageNamed:@"找回密码_03.png"];
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(textField2.frame) + 69.0f / 2, image.size.width / 2, image.size.height / 2)];
    [self.view addSubview:nextBtn];
    nextBtn.center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, nextBtn.center.y);
    [nextBtn setBackgroundImage:image forState:UIControlStateNormal];
    [nextBtn setTitle:@"确认" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(okBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)addBackView:(UITextField *)textField {
    
    CGRect frame = textField.frame;
    frame.size.width = CGRectGetWidth(self.view.frame) - 30;
    frame.origin.x = 15;
    textField.frame = frame;
    textField.backgroundColor = [UIColor whiteColor];
    textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textField.layer.borderWidth = 0.5;
    textField.font = [UIFont systemFontOfSize:15];
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 43.0f / 2, CGRectGetHeight(textField.frame))];
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeAlways;
}

- (void)okBtnAction:(UIButton *)sender {
    
    if (![self.passwordTextField.text isEqual:@""] && [self.passwordTextField.text isEqual:self.repeatTextField.text]) {
        
//        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//        dic[@"user_id"] = self.userID;
//        dic[@"password"] = self.passwordTextField.text;
//        [WLHttpRequestAfter userModifyPasswordWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
//            
//            if ([resultDictionary[@"status"] intValue] == 1) {
        
                [self.navigationController popViewControllerAnimated:YES];
//            }
//            
//        } andFailureBlock:^(NSError *resultError) {
//            
//        }];
    }else {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"输入有误"];
    }
}

@end
